<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/1/19
 * Time: 22:10
 */
namespace app\admin\validate;
use think\Validate;
class User extends Validate{
    //定义规则
    protected $rule = [
        'username' => 'require',        //用户名
        'password' => 'require',        //密码
        'captcha|验证码' => 'require|captcha',
    ];
    //定义提示
    protected $message  =   [
        'username.require'  =>'账号不能为空',
        'password.require'  =>'密码不能为空',
        'captcha.require'  =>'验证码不能为空',
        'captcha.captcha'  =>'验证码错误',
    ];
    //定义场景
    protected $scene = [
        'login' => ['username', 'password'],
    ];

    protected function captcha($value, $id = '',$rule)
    {
        $captcha = new \think\captcha\Captcha();
        return $rule == $captcha->check($value, $id)? true : '验证码错误';
    }
}